package com.ifcar.app.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ifcar.app.util.ThemeSettingsHelper;
import com.ifcar.app.activity.R;

public class HistorySearchAdapter extends BaseAdapter{

	private Context mContext;
	private List<String> mList;
	private LayoutInflater mInflater;
	private ThemeSettingsHelper mThemeSettingsHelper;
	
	public HistorySearchAdapter(Context context, ThemeSettingsHelper themeSettingsHelper, List<String> list){
		mContext = context;
		mList = list;
		mInflater = LayoutInflater.from(context);
		mThemeSettingsHelper = themeSettingsHelper;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(null == convertView){
			convertView = mInflater.inflate(R.layout.search_history_layout, null);
			HolderView holder = new HolderView();
			holder.mHistoryText = (TextView) convertView.findViewById(R.id.search_history_text);
			holder.mSplitView = convertView.findViewById(R.id.bottom_split_line);
			convertView.setTag(holder);
		}
		HolderView holder = (HolderView) convertView.getTag();
		
		String historyStr = (String) getItem(position);
		holder.mHistoryText.setText(historyStr);
		mThemeSettingsHelper.setTextViewColor(mContext, holder.mHistoryText, R.color.list_title_color);
		mThemeSettingsHelper.setViewBackgroud(mContext, holder.mSplitView, R.drawable.list_divider_line);
		return convertView;
	}
	
	class HolderView{
		TextView mHistoryText;
		View mSplitView;
	}

}
